<template>
<div>
<el-table
  :data="tableData"
  border
  height="500"
  style="width: 100%">
  <el-table-column
    fixed
    prop="Sno"
    label="学生编号"
    width="150">
  </el-table-column>
  <el-table-column
    prop="Sname"
    label="学生姓名"
    width="100">
  </el-table-column>
  <el-table-column
    prop="Sdate"
    label="报名时间"
    width="165"
    column-key="Sdate"
    >
  </el-table-column>
  <el-table-column
    prop="Spassword"
    label="密码"
    width="120">
  </el-table-column>
  <el-table-column
    prop="Spayment"
    label="交款额"
    width="120">
  </el-table-column>
  <el-table-column label="操作">
    <template slot-scope="scope">
      <el-button
        size="mini"
        @click="handleEdit(scope.row)">编辑</el-button>
      <el-button
        size="mini"
        type="danger"
        @click="handleDelete(scope.row)">删除</el-button>
    </template>
  </el-table-column>
</el-table>
<el-pagination
  background
  layout="prev, pager, next"
  page-size="6"
  :total="total"
  @current-change="page">
</el-pagination>
</div>
</template>

<script>
export default {
  methods: {
    handleEdit (row) {
      this.$router.push({
        name: 'updateStudent',
        path:'/update',
        query: row
      })
    },
    handleDelete (row) {
      const _this = this
      this.axios.post('http://localhost:8152/api/auth/student/delete',{Sno:row.Sno}).then( (resp)=> {
        _this.$alert(row.Sname+'删除成功！', '消息', {
          confirmButtonText: '确定',
          callback: action => {
            window.location.reload()
          }
        })
      })
    },
    page(){
      const _this = this
      this.axios.post('http://localhost:8181/api/auth/student/findall/').then(function (resp) {
        _this.tableData = resp.data
        _this.total = resp.data
      })
    }
  },
  created () {
    const _this = this;
    this.axios.post('http://localhost:8152/api/auth/student/findall').then((res) => {
      _this.tableData = res.data
      //_this.total = res.data.totalElements
    })
  },
    data () {
      return {
        total: null,
        tableData: null
      }
    }
}
</script>
